<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>截取上传文件的后缀</title>
</head>
<body>
    <form action="" method="post">
        关键字: <input type="text" name="text" id="">
        <input type="submit" name="test" value="测试">
        <input type="submit" name="sub" value="上传">
        <br>
    </form>
</body>
</html>
<?php
/**
 * User: lie
 * Date: 2020-11-10 22:02
 * description:
 */
    // 通过strstr实现截取
    $text = $_POST['text'];
    $test = $_POST['test'];
    $sub = $_POST['sub'];
    // if ($test && $text != ''){
    //     echo strstr($text, ".");
    // } else {
    //     echo "<script>alert('不支持空处理');</script>";
    // }

    // 切割字符串成数组,然后反转获得后缀名
    if ($text){
        $ExplodeStr = explode(".", $text);  // 切割字符串
        $ev = strrev($ExplodeStr[0]);               // 反转字符串
        echo "文件后缀名为: ".$ev;                    // 输出
    }

?>
